#include <stdio.h>
#include <stdlib.h>

#define BODY_BUILDER_TYPE 0
#define BAIL_PLAYING_TYPE 1
#define MY_AUTO_TYPE 2


//相当于c++的派生子类0
typedef struct _BodyBuilder
{
    void(*play)();
}BodyBuilder;

//相当于c++的派生子类1
typedef struct _BailPlaying
{
    void(*playing)();
}BailPlaying;

//相当于c++的派生子类2
typedef struct _MY_AUTO
{
    void(*prinf)();
}MYAUTO;


//相当于c++的基类
typedef struct _PlayRequest
{
 int type;
 //void类型的指针便于转换
 void *pPlaying;
}PlayRequest;

//放置基类进去，在把基类强转回来映射到子类
void person_playing(PlayRequest* pPlayRequest)
{
    if((NULL==pPlayRequest)||(NULL==pPlayRequest->pPlaying))
    {
        return;
    }
    switch (pPlayRequest->type) {
    case BODY_BUILDER_TYPE:
        printf("BODY_BUILDER_TYPE:\n");
        ((BodyBuilder*)pPlayRequest->pPlaying)->play();

        break;
     case BAIL_PLAYING_TYPE:
        printf("BAIL_PLAYING_TYPE:\n");
        ((BailPlaying*)pPlayRequest->pPlaying)->playing();
        break;

    case MY_AUTO_TYPE:
       printf("MY_AUTO_TYPE:\n");
       ((MYAUTO*)pPlayRequest->pPlaying)->prinf();

       break;

    default:
        break;
    }

}

void body_building()
{
    printf("body building!\n");
}

void body_builded()
{
    printf("body builded!\n");
}


void body_prin()
{
    printf("hello myplugin\n");
}

int main()
{
    BodyBuilder bodyBuilder;
    bodyBuilder.play=body_building;


    BailPlaying bodyBuilder1;
    bodyBuilder1.playing=body_builded;

    MYAUTO bodyBuilder2;
    bodyBuilder2.prinf=body_prin;

    PlayRequest request;
    request.type=BODY_BUILDER_TYPE;
    request.pPlaying=&bodyBuilder;
    person_playing(&request);

    PlayRequest request1;
    request1.type=BAIL_PLAYING_TYPE;
    request1.pPlaying=&bodyBuilder1;
    person_playing(&request1);

    PlayRequest request2;
    request2.type=MY_AUTO_TYPE;
    request2.pPlaying=&bodyBuilder2;
    person_playing(&request2);


}

